import java.util.*;

public class Main4 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] num = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            num[i] = in.nextInt();
        }

        for (int i = 0; i < n; i++) {
            for (int j = i; j < n; j++) {
                sum += tryCount(num, i, j);
                // System.out.println(tryCount(num, i, j));
            }
        }
        System.out.println(sum);

    }

    //判断【i，j】区间内的众数 左闭右闭
    private static int tryCount(int[] num, int i, int j) {
        int[] neNum = new int[j - i + 1];
        int m = 0;
        for (int k = i; k <= j; k++) {
            neNum[m] = num[k];
            m++;
        }
        Arrays.sort(neNum);

        Map<Integer, Integer> map = new HashMap<>();
        for (int i1 : neNum) {
            map.put(i1, map.getOrDefault(i1, 0) + 1);
        }

        //取出 map 中 value 最大的 key；
        int maxValue = 0;
        int ke = neNum[0];
        for (Integer key : map.keySet()) {
            if (map.get(key) > maxValue) {
                maxValue = map.get(key);
                ke = key;
            }
        }
        return ke;
    }
}
